package com.tanhua.server.controller;

import com.alibaba.fastjson.JSON;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.SoulVo;
import com.tanhua.model.vo.AnswerVo;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.SoulVo;
import com.tanhua.server.service.TestSoulService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测灵魂
 *
 * @author youshengfeng
 * @date 2022/2/20 上午 10:50
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 提交问卷
     *
     * @param answers
     * @return
     */
    @PostMapping
    public ResponseEntity handIn(@RequestBody Map<String,List<AnswerVo>> answers) {
        //调用业务层
        String objectId = testSoulService.handIn(answers);
        //返回
//        String string = objectId.toString();
        //  return ResponseEntity.ok(JSON.toJSON(objectId));
//        Map<String,String> map = new HashMap<>();
//        map.put("reportId",string);
        return ResponseEntity.ok(objectId);
    }

    /**
     * 灵魂测试-查看结果
     *
     * @param ReportId
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity<SoulVo> SoulReport(@PathVariable("id") String  ReportId) {
        SoulVo soulVo = testSoulService.findSoulReport(ReportId);
        return ResponseEntity.ok(soulVo);
    }

    /**
     * 获取问卷列表
     */
    @GetMapping
    public ResponseEntity testSoul(){
        List<QuestionnaireVo> list = testSoulService.getQuestionnaireIdList();
        return ResponseEntity.ok(list);
    }

}
